package xine.demo.ssm.entity;
//package xine.demo.spring.entity;
//
//import com.sun.xml.internal.fastinfoset.algorithm.BuiltInEncodingAlgorithm;
//import org.apache.poi.hssf.usermodel.HSSFCellStyle;
//import org.apache.poi.hssf.usermodel.HSSFFont;
//import org.apache.poi.ss.usermodel.*;
//import org.springframework.web.servlet.view.document.AbstractExcelView;
//import org.springframework.web.servlet.view.document.AbstractXlsView;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.OutputStream;
//import java.net.URLEncoder;
//import java.util.Map;
//
//public class TestExcelPOIView extends AbstractXlsView {
//
//    //private static Logger logger = LoggerFactory.getLogger(TestExcelPOIView.class);
//
//
//    //用于创建Excel文档
//    @Override
//    protected void buildExcelDocument(Map<String, Object> model, Workbook workbook, HttpServletRequest request, HttpServletResponse response) throws Exception {
//
//        OutputStream os = null;
//        try {
//
//            String filename = (String)model.get("filename");
//            response.setContentType("APPLICATION/OCTET-STREAM");
//            response.setHeader("Content-Disposition",  "attachment; filename=" + URLEncoder.encode(filename, "UTF-8"));
//            os = response.getOutputStream();
//
//            Sheet sheet = workbook.createSheet("资产信息");
//            PoiExcelUtils.addTitle(sheet, showName, "资产信息", getHeader(workbook), getContext(workbook));
//            @SuppressWarnings("unchecked")
//            List<MObject> list = (List<MObject>) model.get("items");
//            PoiExcelUtils.addContextByList(sheet, list, fieldName, getContext(workbook), true);
//            workbook.write(os);
//        } catch (Throwable e) {
//            logger.error("资产信息导出出错：" + e.getMessage(), e);
//        } finally {
//            try {
//                os.flush();
//                os.close();
//            } catch (Throwable e) {
//                logger.error("资产信息导出Excel出错：" + e.getMessage(), e);
//            }
//        }
//    }
//
//    //标题样式
//    public static CellStyle getHeader(Workbook workbook){
//
//        CellStyle format = workbook.createCellStyle();
//        Font font = workbook.createFont();
//        font.setBold(true);  //加粗
//        font.setFontName("黑体");
//        font.setFontHeightInPoints((short)16);
//        format.setVerticalAlignment(VerticalAlignment.CENTER);
//        format.setAlignment(HorizontalAlignment.CENTER);
//        format.setFont(font);
//        return format;
//    }
//
//    //内容样式
//    public static CellStyle getContext(Workbook workbook){
//        CellStyle format = workbook.createCellStyle();
//        Font font = workbook.createFont();
//        font.setFontName("宋体");
//        format.setVerticalAlignment(VerticalAlignment.CENTER);
//        format.setAlignment(HorizontalAlignment.CENTER);
//        format.setFont(font);
//        return format;
//    }
//
//}